package com.preguicoso.client.estabelecimento.cardapio;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.Image;
import com.preguicoso.client.estabelecimento.cardapio.modelosItens.BuildItem;
import com.preguicoso.client.estabelecimento.cardapio.modelosItens.Tipo;
import com.preguicoso.client.estabelecimento.carrinho.CarrinhoPedidosUI;
import com.preguicoso.client.telaInicial.lightBox;
import com.preguicoso.shared.entities.ItemCardapioBean;
import com.preguicoso.shared.utils.MoneyUtils;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.uibinder.client.UiHandler;

public class CardapioItem extends Composite {

	private static CardapioItemUiBinder uiBinder = GWT
			.create(CardapioItemUiBinder.class);
	@UiField
	Label prato;
	@UiField
	InlineLabel preco;
	@UiField
	HTMLPanel botaoAdd;
	@UiField Image imagem;
	@UiField FocusPanel focusPanel;
	@UiField InlineLabel codigo;
	@UiField InlineLabel descricao;

	interface CardapioItemUiBinder extends UiBinder<Widget, CardapioItem> {
	}

	public CardapioItem() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	ItemCardapioBean i;
	public CardapioItem(String prato, String descricao, String preco,
			HTMLPanel botao) {
		initWidget(uiBinder.createAndBindUi(this));
		this.prato.setText(prato);
		this.preco.setText(preco);
		this.botaoAdd.add(botao);
	}
	public CardapioItem(ItemCardapioBean e) {
		initWidget(uiBinder.createAndBindUi(this));
		this.prato.setText(e.getNome());
		i=e;
		codigo.setText(e.getNumero()+"");
		this.descricao.setText(e.getDescricao());
		this.preco.setText(MoneyUtils.parseString(e.getPreco()));
		this.imagem.setUrl(e.getImagem());
		//this.imagem.setWidth("60px");
	}
	
	
	CarrinhoPedidosUI carrinho;
	public void setCarrinho(CarrinhoPedidosUI c){
		carrinho = c;
	}

	private final CardapioServiceAsync cardapioService = GWT
			.create(CardapioService.class);
	

	@UiHandler("focusPanel")
	void onFocusPanelClick(ClickEvent event) {
		if(Window.getClientWidth()>500)
			lightBox.getInstance().show(BuildItem.getInstance().getItem(i),460, 400);
		else
			lightBox.getInstance().show(BuildItem.getInstance().getItem(i),"85%", "67%");
		//adicionarItemAoCarrinho(i);
	}
}
